#ifndef UDPBASE_H
#define UDPBASE_H

#include <QObject>
#include <QUdpSocket>
#include <QNetworkInterface>
#include <QNetworkDatagram>

#include "myini.h"

// 定义UDP数据结构
struct UdpData {
    QString srcIp;
    quint16 srcPort;
    QByteArray data;
    int width;
    int height;
};

class UdpBase : public QObject
{
    Q_OBJECT
public:
    explicit UdpBase(QObject *parent = nullptr);

//------------------------------函数定义---------------------------------//

    virtual void startProcess() = 0;  //开始接收和重组

    virtual void stopProcess() = 0;   //停止接收和重组

    virtual void setTargetFps(int fps) = 0; //设置从接收端到编码端的帧率

    int getNetCardIndex(QString interfaceName); //获取网卡index

    QNetworkInterface getNetInterface(QString ip);  //获取网络接口

    void setConfig(ENCODE_PARAM m_cfg);    //设置ini网络配置内容

public slots:
    virtual void onInitUdp(){}       //初始化

signals:
    void sigToEncodeImg(const QByteArray& imgArray);

    void sigToSend(const QByteArray& imgArray);

    void sigErrorOccurred(const QString &errorString);

//------------------------------变量定义---------------------------------//

public:
    QUdpSocket *m_udpReceive;   //udp接收套接字

    QString m_bindIP = "";   //绑定本地ip

    quint16 m_bindPort = 0; //绑定本地port

    QString m_srcIP = "";   //源ip

    quint16 m_srcPort = 0;  //源端口

    int m_netCardIndex = 0; //网卡的索引

    bool m_runStatus = false; //设置运行状态标识

};

#endif // UDPBASE_H
